package com.smartscreen.contentmanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.smartscreen.contentmanage.entity.Notice;
import com.smartscreen.contentmanage.mapper.NoticeMapper;
import com.smartscreen.contentmanage.service.NoticeService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
    
    @Override
    public IPage<Notice> getNoticeList(int page, int pageSize, String status) {
        Page<Notice> pageParam = new Page<>(page, pageSize);
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        
        if (StringUtils.hasText(status)) {
            queryWrapper.eq("status", status);
        }
        
        queryWrapper.orderByDesc("created_at");
        
        return this.page(pageParam, queryWrapper);
    }
}